﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.WmsManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.WmsManagement.OutboundVMs
{
    public partial class OutboundListVM : BasePagedListVM<Outbound_View, OutboundSearcher>
    {
        
        protected override IEnumerable<IGridColumn<Outbound_View>> InitGridHeader()
        {
            return new List<GridColumn<Outbound_View>>{
                
                this.MakeGridHeader(x => x.Outbound_SheetId).SetTitle(@Localizer["Page.出库单号"].Value),
                this.MakeGridHeader(x => x.Outbound_SheetNo).SetTitle(@Localizer["Page.出库单号"].Value),
                this.MakeGridHeader(x => x.Outbound_OutMode).SetTitle(@Localizer["Page.出库方式"].Value),
                this.MakeGridHeader(x => x.Outbound_Wo).SetTitle(@Localizer["Page.生产工单"].Value),
                this.MakeGridHeader(x => x.Outbound_Sn).SetTitle(@Localizer["Page.追溯码"].Value),
                this.MakeGridHeader(x => x.Outbound_Material).SetTitle(@Localizer["Page.物料"].Value),
                this.MakeGridHeader(x => x.Outbound_StoreQty).SetTitle(@Localizer["Page.在库数量"].Value),
                this.MakeGridHeader(x => x.Outbound_OutQty).SetTitle(@Localizer["Page.出库数量"].Value),
                this.MakeGridHeader(x => x.Outbound_OutOperator).SetTitle(@Localizer["Page.出库"].Value),
                this.MakeGridHeader(x => x.Outbound_OutboundDate).SetTitle(@Localizer["Page.出库时间"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<Outbound_View> GetSearchQuery()
        {
            var query = DC.Set<Outbound>()
                
                .CheckEqual(Searcher.SheetId, x=>x.SheetId)
                .CheckContain(Searcher.SheetNo, x=>x.SheetNo)
                .CheckEqual(Searcher.OutMode, x=>x.OutMode)
                .CheckContain(Searcher.Wo, x=>x.Wo)
                .CheckContain(Searcher.Sn, x=>x.Sn)
                .CheckEqual(Searcher.MaterialId, x=>x.MaterialId)
                .CheckEqual(Searcher.StoreQty, x=>x.StoreQty)
                .CheckEqual(Searcher.OutQty, x=>x.OutQty)
                .CheckContain(Searcher.OutOperator, x=>x.OutOperator)
                .CheckBetween(Searcher.OutboundDate?.GetStartTime(), Searcher.OutboundDate?.GetEndTime(), x => x.OutboundDate, includeMax: false)
                .Select(x => new Outbound_View
                {
				    ID = x.ID,
                    
                    Outbound_SheetId = x.SheetId,
                    Outbound_SheetNo = x.SheetNo,
                    Outbound_OutMode = x.OutMode,
                    Outbound_Wo = x.Wo,
                    Outbound_Sn = x.Sn,
                    Outbound_Material = x.Material.TenantCode,
                    Outbound_StoreQty = x.StoreQty,
                    Outbound_OutQty = x.OutQty,
                    Outbound_OutOperator = x.OutOperator,
                    Outbound_OutboundDate = x.OutboundDate,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class Outbound_View: Outbound
    {
        
        public long? Outbound_SheetId { get; set; }
        public string Outbound_SheetNo { get; set; }
        public InOutEnum? Outbound_OutMode { get; set; }
        public string Outbound_Wo { get; set; }
        public string Outbound_Sn { get; set; }
        public string Outbound_Material { get; set; }
        public decimal? Outbound_StoreQty { get; set; }
        public decimal? Outbound_OutQty { get; set; }
        public string Outbound_OutOperator { get; set; }
        public DateTime? Outbound_OutboundDate { get; set; }

    }

}